package LeetCode.month01.day27;

public class No2653 {
    public static void main(String[] args) {

    }
    public static int[] getSubarrayBeauty(int[] nums, int k, int x) {
        int len = nums.length;
        int[] cnt = new int[101];
        int[] res = new int[len-k+1];
        for (int i = 0; i < k-1; i++) {
            cnt[nums[i]+50]++;
        }
        for (int i = k-1; i < len; i++) {
            cnt[nums[i]+50]++;
            int left = x;
            for (int j = 0; j < 50; j++) {
                left-=cnt[j];
                if(left<=0) {
                    res[i-k+1]=j-50;
                    break;
                }
            }
            if(left>0) res[i-k+1]=0;
            cnt[nums[i-k+1]+50]--;
        }
        return res;
    }
}
